package top.zhaojx.rpc.loadbalance.impl;

import top.zhaojx.rpc.entity.RpcRequest;
import top.zhaojx.rpc.loadbalance.AbstractLoadBalancer;
import java.util.List;
import java.util.Random;

/**
 * 很多负载均衡默认的实现，如RocketMQ中生产者提供
 */
public class RandomLoadBalancer extends AbstractLoadBalancer {

    @Override
    protected String doSelect(List<String> serviceAddresses, RpcRequest rpcRequest) {
        return serviceAddresses.get(new Random().nextInt(serviceAddresses.size()));
    }
}
